package com.yotoodesign.dianba.util;

import java.util.Calendar;
import java.util.Date;

public class WeiboUtil {
	/**
	 * 
	 * @param time
	 * @return 当前时间与微博发送时间的差值
	 */
	public static String calcTime(String time) {
		/* 返回计算的时间 */
		String returnTime = null;

		/* 设置微博发布时间信息 */
		Date currentTime = Calendar.getInstance().getTime();
		Date weiboTime = new Date(time);

		long interval = (currentTime.getTime() - weiboTime.getTime()) / 1000;

		long day = interval / (24 * 3600);// 天
		long hour = interval % (24 * 3600) / 3600;// 小时
		long minute = interval % 3600 / 60;// 分钟
		long second = interval % 60;// 秒

		if (day >= 1) {
			if (day >= 3) {
				returnTime = currentTime.getMonth() + "-"
						+ currentTime.getDay() + " " + currentTime.getHours()
						+ ":" + currentTime.getMinutes();
			} else {
				returnTime = day + "天前";
			}

		} else if (hour >= 1 && hour < 24) {
			returnTime = hour + "小时前";
		} else if (minute >= 1 && minute < 60) {
			returnTime = minute + "分钟前";
		} else if (second < 60) {
			returnTime = second + "秒前";
		}

		return returnTime;

	}
}
